/************************************************************************

								Heroes IV
					  Copyright 2000, The 3DO Company

	------------------------------------------------------------------
  						       combat_obstacle_placer.h

	$Header: /game/combat_obstacle_placer.h $

	$NoKeywords: $

 ************************************************************************/
#ifndef COMBAT_OBSTACLE_PLACER_H_INCLUDED
#define COMBAT_OBSTACLE_PLACER_H_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "combat_object_model.h"
#include "combat_obstacle_data.h"
#include "isometric_map.h"
#include "map_point_list.h"
#include "obstacle_type.h"
#include "terrain.h"

class  t_battlefield;
class  t_combat_object_model_base;
struct t_map_rect_2d;

// ------------------------------------------------------------------
// obstacle data
// ------------------------------------------------------------------

struct t_obstacle_weight
{
	t_combat_header_obstacle_data const* obstacle;
	int					   weight;
};

// ------------------------------------------------------------------
// obstacle weighting data
// ------------------------------------------------------------------
struct t_obstacle_weighting
{
	int terrain[k_basic_terrain_count];
	int adjacent[k_obstacle_type_count];
	int overlap[k_obstacle_type_count];
};

typedef std::list<t_obstacle_weight> t_obstacle_weight_list;


struct t_obstacle_placer_data
{
	bool	  can_be_blocked;
	bool	  blocked;
	bool	  visited;
	t_uint16  obstacle_chance;
	int		  adjacent[k_obstacle_type_count];
	int		  overlap[k_obstacle_type_count];

	t_obstacle_placer_data();
};

// --------------------------------------------------------------------
// object to place combat obstacles
// --------------------------------------------------------------------
class t_combat_obstacle_placer
{
public:
	t_combat_obstacle_placer( t_battlefield& battlefield, bool has_castle, int castle_row );

	void execute();
protected:
	typedef t_obstacle_placer_data t_data;

	void clear_rect( t_map_rect_2d const& rect );
	void clear_start_positions();
	void cut_path( t_map_point_2d const& start_point, t_map_point_2d const& end_point,
		           int width );
	void cut_path( int size );
	void cut_paths();
	void examine( t_map_point_2d const& center );
	int  get_weight( t_combat_object_model_base const&	obstacle,
					 t_map_point_2d const&				center ) const;
	void place_obstacle( std::string const& name,
					     t_map_point_2d const& center );
	void push_points( t_map_point_2d const& center, int size );
	void push_points( t_map_rect_2d const& object_rect, int size );

	t_battlefield&			m_battlefield;
	int						m_castle_row;
	t_isometric_map<t_data> m_data;
	bool					m_has_castle;
	t_map_point_2d_list		m_open_points;
};

t_obstacle_data_array const& get_obstacle_data();
t_obstacle_weighting const&  get_weighting( t_obstacle_type type );

#endif // COMBAT_OBSTACLE_PLACER_H_INCLUDED